import request from '@/utils/request';

/**
 * 2.16.1 用户补券列表查询 /coupon-config/supplycoupon/search
 */
export async function supplycouponSearch(data: API.SupplycouponInfo, options?: API.baseOption) {
  return request<API.BasePaginationRes<API.SupplycouponListItem>>('/supplycoupon/search', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 2.16.2 用户补券 /coupon-config/supplycoupon/supply
 */
export async function supplycouponSupply(data: API.SupplyInfo, options?: API.baseOption) {
  return request<any>('/supplycoupon/supply', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 2.16.3 验证发放 /coupon-config/supplycoupon/check
 */
export async function supplycouponCheck(
  data: { activityId: string; mobile: string; placeChannelId: string },
  options?: API.baseOption,
) {
  return request<any>('/supplycoupon/check', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 2.18.1 券列表 /coupon-config/coupon/search
 */
export async function couponSearch(data: API.CouponSearchInfo, options?: API.baseOption) {
  return request<API.BasePaginationRes<API.CouponSearchListItem>>('/coupon/search', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 2.18.2 一键归档/coupon-config/coupon/archive
 */
export async function couponArchive(
  data: { userCode: string; mobile: string; brand: string },
  options?: API.baseOption,
) {
  return request<any>('/coupon/archive', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 2.18.3 券汇总/coupon-config/coupon/summarize
 */
export async function couponSummarize(
  data: { userCode: string; mobile: string; brand: string },
  options?: API.baseOption,
) {
  return request<any>('/coupon/summarize', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
 * 2.18.4 账号迁移/coupon-config/coupon/account-move
 */
export async function accountMove(
  data: { oldUserCode: string; newUserCode: string },
  options?: API.baseOption,
) {
  return request<any>('/coupon/account-move', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.5 批量查询/coupon-config/coupon/search-batch
 */
export async function searchBatch(data: { fileUrl: string }, options?: API.baseOption) {
  return request<any>('/coupon/search-batch', {
    responseType: 'blob',
    getResponse: true,
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.6 批量核销/coupon-config/coupon/usecoupon-batch
 */
export async function usecouponBatch(
  data: { fileUrl: string; activityId: string },
  options?: API.baseOption,
) {
  return request<any>('/coupon/usecoupon-batch', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.7 核销流水/coupon-config/coupon/used-history
 */
export async function usedHistory(data: { couponCode: string }, options?: API.baseOption) {
  return request<any>('/coupon/used-history', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.8 券操作/coupon-config/coupon/modify-coupon
 */
export async function modifyCoupon(
  data: {
    couponCode: string;
    operationFlag: number;
    storeId: string;
    validStartTime: string;
    validEndTime: string;
  },
  options?: API.baseOption,
) {
  return request<any>('/coupon/modify-coupon', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.9 查询相同订单/coupon-config/coupon/search-same-order
 */
export async function searchSameOrder(
  data: {
    merchantPosTransId: string;
    userCode: string;
  },
  options?: API.baseOption,
) {
  return request<any>('/coupon/search-same-order', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.10 清除当天限制/coupon-config/coupon/clean-day-limit
 */
export async function cleanDayLimit(
  data: {
    activityId: string;
    userCode: string;
  },
  options?: API.baseOption,
) {
  return request<any>('/coupon/clean-day-limit', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.11 纠正次数/coupon-config/coupon/check-used-seqid
 */
export async function checkUsedSeqid(
  data: {
    userCode: string;
    activityId: string;
    couponCode: string;
    usedSeqId: string;
    reusableCount: string;
  },
  options?: API.baseOption,
) {
  return request<any>('/coupon/check-used-seqid', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.12 检查次数/coupon-config/coupon/revoke-count
 */
export async function revokeCount(
  data: {
    couponCode: string;
  },
  options?: API.baseOption,
) {
  return request<any>('/coupon/revoke-count', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

/**
2.18.13 取消预约/coupon-config/coupon/book-cancel
 */
export async function bookCancel(
  data: {
    couponCode: string;
  },
  options?: API.baseOption,
) {
  return request<any>('/coupon/book-cancel', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}
